package com.crm.ServiceImpl;

import com.crm.Service.CustomerService;
import com.crm.dao.CustomerDao;
import com.crm.daoImpl.CustomerDaoImpl;
import com.crm.pojo.Customer;
import com.crm.pojo.CustomerDetail;

import java.sql.SQLException;
import java.util.List;

/**
 * @version : 1.0
 * @auther : hjx
 * @Date : 2021/6/25
 * @Description : 实训
 */
public class CustomerServiceImpl implements CustomerService {

    @Override
    public boolean addCustomer(Customer cc, CustomerDetail ccd) throws SQLException {

        CustomerDao customerDao = new CustomerDaoImpl();
        Boolean a = customerDao.addCustomer(cc.getCustName(), cc.getCustSource(), cc.getCustIndustry(),
                cc.getCustLevel(), cc.getCustPhone(), cc.getCustMobile(), ccd.getCustRegion(),
                ccd.getCustCapital(), ccd.getCustAddress(), ccd.getCustZip(), ccd.getCustFax(),
                ccd.getCustWebsite(), ccd.getCustLicence(), ccd.getCustPic(),
                ccd.getCustCorporation(), ccd.getCustBank());

        if (a) {
            return true;
        }
        return false;
    }

    @Override
    public List<Customer> allCustomers(int start, int pagesize) {
        CustomerDao customerDao = new CustomerDaoImpl();
        List<Customer> customers = customerDao.queryCustomer(start, pagesize);
        return customers;
    }

    /**
     * 返回所有客户名字
     * @return
     */
    @Override
    public List<String> queryCname() {
        CustomerDao customerDao = new CustomerDaoImpl();
        List<String> strings = customerDao.queryCustomerName();
        return strings;
    }

    @Override
    public boolean delCustomer(int id) {
        CustomerDao customerDao = new CustomerDaoImpl();
        customerDao.deleteCustomer(id);
        return true;
    }

    @Override
    public Customer getCs(Integer cid) {
        return null;
    }

    @Override
    public CustomerDetail getCsD(Integer cid) {
        return null;
    }

    @Override
    public boolean upCustomer(Customer cc, CustomerDetail ccd) {
        return false;
    }

    @Override
    public List<Customer> queryCustomByName(String name) {
        CustomerDao customerDao = new CustomerDaoImpl();
        List<Customer> customers = customerDao.queryCustomByName(name);
        return customers;
    }

    @Override
    public Customer queryCustomById(int id) {
        CustomerDao customerDao = new CustomerDaoImpl();
        Customer customer = customerDao.queryCustomById(id);
        return customer;
    }

    @Override
    public CustomerDetail queryCustomDetailById(int id) {
        CustomerDao customerDao = new CustomerDaoImpl();
        CustomerDetail customerDetail = customerDao.queryCustomDetailById(id);
        return customerDetail;
    }

    @Override
    public void updateCustomer(int custId, String custName, String custSource, String custIndustry, String custLevel, String custPhone, String custMobile, String custRegion, long custCapital, String custAddress, String custMemo, String custFax, String custWebsite, String custLicence, String custPic, String custCorporation, String custBank) {
        CustomerDao customerDao = new CustomerDaoImpl();
        customerDao.updateCustomer(custId, custName, custSource, custIndustry, custLevel, custPhone, custMobile, custRegion, custCapital, custAddress, custMemo, custFax, custWebsite, custLicence, custPic, custCorporation, custBank);
    }
}
